package com.ruoyi.web.controller.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.HospitalSubscribeMedicalExaminerInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HospitalSubscribeMedicalExamType;
import com.ruoyi.system.service.IHospitalSubscribeMedicalExamTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 体检项目类型Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/admin/type")
public class HospitalSubscribeMedicalExamTypeAdminController extends BaseController
{
    @Autowired
    private IHospitalSubscribeMedicalExamTypeService hospitalSubscribeMedicalExamTypeService;

    /**
     * 查询体检项目类型列表
     *@response {@link HospitalSubscribeMedicalExamType}
     */
    @GetMapping("/list")
    public TableDataInfo list(HospitalSubscribeMedicalExamType hospitalSubscribeMedicalExamType)
    {
        startPage();
        List<HospitalSubscribeMedicalExamType> list = hospitalSubscribeMedicalExamTypeService.selectHospitalSubscribeMedicalExamTypeList(hospitalSubscribeMedicalExamType);
        return getDataTable(list);
    }

    /**
     * 导出体检项目类型列表
     */
    @Log(title = "体检项目类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HospitalSubscribeMedicalExamType hospitalSubscribeMedicalExamType)
    {
        List<HospitalSubscribeMedicalExamType> list = hospitalSubscribeMedicalExamTypeService.selectHospitalSubscribeMedicalExamTypeList(hospitalSubscribeMedicalExamType);
        ExcelUtil<HospitalSubscribeMedicalExamType> util = new ExcelUtil<HospitalSubscribeMedicalExamType>(HospitalSubscribeMedicalExamType.class);
        util.exportExcel(response, list, "体检项目类型数据");
    }

    /**
     * 获取体检项目类型详细信息
     * @response {@link HospitalSubscribeMedicalExamType}
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(hospitalSubscribeMedicalExamTypeService.selectHospitalSubscribeMedicalExamTypeById(id));
    }

    /**
     * 新增体检项目类型
     */
    @Log(title = "体检项目类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HospitalSubscribeMedicalExamType hospitalSubscribeMedicalExamType)
    {
        return toAjax(hospitalSubscribeMedicalExamTypeService.insertHospitalSubscribeMedicalExamType(hospitalSubscribeMedicalExamType));
    }

    /**
     * 修改体检项目类型
     */
    @Log(title = "体检项目类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HospitalSubscribeMedicalExamType hospitalSubscribeMedicalExamType)
    {
        return toAjax(hospitalSubscribeMedicalExamTypeService.updateHospitalSubscribeMedicalExamType(hospitalSubscribeMedicalExamType));
    }

    /**
     * 删除体检项目类型
     */
    @Log(title = "体检项目类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hospitalSubscribeMedicalExamTypeService.deleteHospitalSubscribeMedicalExamTypeByIds(ids));
    }

    /**
     * 启用 该类型下所有套餐启用
     */
    @PostMapping("/star")
    public AjaxResult star(@RequestBody HospitalSubscribeMedicalExamType hospitalSubscribeMedicalExamType)
    {
        hospitalSubscribeMedicalExamTypeService.starOrStopById(hospitalSubscribeMedicalExamType.getId(),0);
        return success();
    }

    /**
     * 禁用 该类型下所有套餐禁用
     */
    @PostMapping("/stop")
    public AjaxResult stop(@RequestBody HospitalSubscribeMedicalExamType hospitalSubscribeMedicalExamType)
    {
        hospitalSubscribeMedicalExamTypeService.starOrStopById(hospitalSubscribeMedicalExamType.getId(),1);
        return success();
    }
}
